home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / flilib.zip / FLISRC.ZIP / FLIUNTIL.C < prev    next >
C/C++ Source or Header  |  1989-11-16  |  1KB  |  61 lines

  1.  
  2. #include "aafli.h"
  3. #include "aaclock.h"
  4.  
  5. Errval fli_until(char *fliname,     /* name of fli to play */
  6.     int speed,
  7.     AAivec until)        /* function to call to see when to stop */
  8. {
  9. Jfile ff;
  10. Fli_head fhead;
  11. long frame1off;
  12. int err;
  13. int frame;
  14. int loop = 0;
  15. int i;
  16. long time, last_time, dest_time;
  17. int cur_frame;
  18.  
  19. aa_goclock();
  20. if ((ff = fli_open(fliname, &fhead)) < 0)
  21.     return((Errval)ff);
  22. cur_frame = 0;
  23. if (!(*until)(cur_frame, (int)fhead.frame_count, loop))
  24.     goto OUT;
  25. if ((err = fli_next_frame(ff)) >= AA_SUCCESS)
  26.     {
  27.     frame1off = dos_tell (ff);
  28.     }
  29. last_time = aa_getclock();
  30. if (speed < 0)
  31.     speed = fhead.speed;
  32. speed *= AA_CLOCK_SCALE;
  33. for (;;)
  34.     {
  35.     dos_seek (ff, frame1off, DOS_SEEK_START);
  36.     for (i=0;i<fhead.frame_count;i++)
  37.         {
  38.         cur_frame++;
  39.         dest_time = last_time + speed;
  40.         for (;;)    /* busy busy busy wait until it's time... */
  41.             {
  42.             if (!(*until)(cur_frame, (int)fhead.frame_count, loop))
  43.                 goto OUT;
  44.             time = aa_getclock();
  45.             if (time >= dest_time)
  46.                 {
  47.                 last_time = time;
  48.                 break;
  49.                 }
  50.             }
  51.         if ((err = fli_next_frame(ff)) < AA_SUCCESS)
  52.             goto OUT;
  53.         }
  54.     loop++;
  55.     }
  56. OUT:
  57. dos_close (ff);
  58. return(err);
  59. }
  60.  
  61.